package ngames.com.sushitv.temp.Thread;

import android.app.Activity;
import android.os.SystemClock;
import android.support.v4.view.ViewPager;
import android.util.Log;

/**
 * Created by edmond on 16-7-31.
 */
public class FeaturedBannerThread extends Thread{
    boolean isStop = false;
    ViewPager viewPager;
    Activity activity;
    int time;

    static int threadCount = 0;

    public FeaturedBannerThread(Activity activity, ViewPager viewPager, int time){
        this.activity = activity;
        this.viewPager = viewPager;
        this.time = time;
    }
    @Override
    public void run() {
        threadCount++;
        super.run();
        while(!isStop){
            SystemClock.sleep(time);
            if(threadCount>1){
                continue;
            }
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Log.d("Index", String.valueOf(viewPager.getCurrentItem()));
                    viewPager.setCurrentItem(viewPager.getCurrentItem()+1);
                }
            });
        }
        threadCount--;
        Log.d("FeaturedBannerThread","stop");
    }
    public void setStop(){
        isStop = true;
    }
}
